.<template>
  <div class="edit">
      <div class="top"><h3>编辑地址</h3></div>
      <div class="main">
          <div><input type="text" v-model="name" placeholder="请输入姓名"></div>
          <div><input type="text" v-model="tel" placeholder="请输入电话"></div>
          <div><input type="text" v-model="addr" placeholder="请输入地址"></div>
          <div><button @click="editinfo">确定</button></div>
      </div>
  </div>
</template>

<script>
import axios from 'axios'
export default {
    async mounted () {
        let {id} = this.$route.query;
        let res =await axios.post('/api/echo',{id});
        this.name=res.data.data[0].name;
        this.tel=res.data.data[0].tel;
        this.addr=res.data.data[0].addr;
    },
    data () {
        return {
            name:'',
            tel:'',
            addr:''
        }
    },
    methods: {
        async editinfo(){
            let {id} = this.$route.query;
            let reg=/^1[3-9]\d{9}/g;
            if(this.name!=''&&this.tel!=''&&reg.test(this.tel)&&this.addr!=''){
                   axios.post('/api/edit',{
                        id:id,
                        name:this.name,
                        tel:this.tel,
                        addr:this.addr
                    }).then(res=>{
                        console.log(res);
                        this.$router.go(-1)
                    })
            }else{
                alert('请填写正确信息')
            }
        }
    }
}
</script>

<style lang='scss'>
.edit{
    width: 100%;
    height: 100%;
    .top{
        width: 100%;
        height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
        background: cornflowerblue;
    }
    .main{
        width: 100%;
        height: calc(100% - 44px);
        display: flex;
        align-items: center;
        flex-direction: column;
        input{
            width: 200px;
            height: 30px;
            margin: 5px 0;
            text-indent: 1em;
            outline: none;
            border-radius: 5px;

        }
        button{
            width: 150px;
            height: 30px;
            outline: none;
            border-radius: 5px;
        }
    }
}
</style>